<?php


/*
 * Created on 8 Aug 2007
 *
 * @author Constantine Didenko
 * 
 */

class BaseComponent {

	var $childs = null;

	var $content = null;

	var $parent = null;

	var $template = null;

	function BaseComponent() {

	}

	function setChilds($childs) {
		$this->childs = $childs;
	}

	function getChilds() {
		return $this->childs;
	}

	function setContent($content) {
		$this->content = $content;
	}

	function setParent($parent) {
		$this->parent = $parent;
	}

	function getParent() {
		return $this->parent;
	}

	function prepareHTML() {
		isset ($this->content) ? $keys = array_keys($this->content) : $keys = null;
		$result = $this->template;
		for ($i = 0; $i < count($keys); $i++) {
			$result = str_replace($keys[$i], $this->content[$keys[$i]], $result);
		}
		return $result;
	}

	function setTemplate($template) {
		$this->template = file_get_contents($template);
	}

	function getHTML() {
		for ($i = 0; $i = count($this->childs); $i++) {
			$this->childs[$i]->render();
		}
		return $this->prepareHTML();
	}

	function render() {
		echo $this->getHTML();
	}

}
?>
